]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
ShellEntry: make isPassword param changeable at runtime
authorGiovanni Campagna <gcampagna@src.gnome.org>
Sun, 27 May 2012 17:06:08 +0000 (19:06 +0200)
committerGiovanni Campagna <gcampagna@src.gnome.org>
Sat, 21 Jul 2012 13:40:27 +0000 (15:40 +0200)
Make it possible to control the visibility of "Show/hide text" item
at runtime, to reuse the same entry for both password and non-password
prompts.

https://bugzilla.gnome.org/show_bug.cgi?id=619955

js/ui/shellEntry.js

index e348a80b7ff7752c85e05923ea55fe4fd81b4f2c..90b313f583904b7ff59549d7c763fafba107a396 100644 (file)
@@ -7,7 +7,7 @@ const Main = imports.ui.main;
 const Params = imports.misc.params;
 const PopupMenu = imports.ui.popupMenu;
 
-const _EntryMenu = new Lang.Class({
+const EntryMenu = new Lang.Class({
     Name: 'ShellEntryMenu',
     Extends: PopupMenu.PopupMenu,
 
@@ -34,18 +34,37 @@ const _EntryMenu = new Lang.Class({
         this._pasteItem = item;
 
         this._passwordItem = null;
-        if (params.isPassword) {
-            item = new PopupMenu.PopupMenuItem('');
-            item.connect('activate', Lang.bind(this,
-                                               this._onPasswordActivated));
-            this.addMenuItem(item);
-            this._passwordItem = item;
-        }
+        if (params.isPassword)
+           this._makePasswordItem();
 
         Main.uiGroup.add_actor(this.actor);
         this.actor.hide();
     },
 
+    _makePasswordItem: function() {
+        let item = new PopupMenu.PopupMenuItem('');
+        item.connect('activate', Lang.bind(this,
+                                           this._onPasswordActivated));
+        this.addMenuItem(item);
+        this._passwordItem = item;
+    },
+
+    get isPassword() {
+       return this._passwordItem != null;
+    },
+
+    set isPassword(v) {
+       if (v == this.isPassword)
+           return;
+
+       if (v)
+           this._makePasswordItem();
+       else {
+           this._passwordItem.destroy();
+           this._passwordItem = null;
+       }
+    },
+
     open: function() {
         this._updatePasteItem();
         this._updateCopyItem();
@@ -104,50 +123,50 @@ const _EntryMenu = new Lang.Class({
 function _setMenuAlignment(entry, stageX) {
     let [success, entryX, entryY] = entry.transform_stage_point(stageX, 0);
     if (success)
-        entry._menu.setSourceAlignment(entryX / entry.width);
+        entry.menu.setSourceAlignment(entryX / entry.width);
 };
 
 function _onClicked(action, actor) {
-    let entry = actor._menu ? actor : actor.get_parent();
+    let entry = actor.menu ? actor : actor.get_parent();
 
-    if (entry._menu.isOpen) {
-        entry._menu.close();
+    if (entry.menu.isOpen) {
+        entry.menu.close();
     } else if (action.get_button() == 3) {
         let [stageX, stageY] = action.get_coords();
         _setMenuAlignment(entry, stageX);
-        entry._menu.open();
+        entry.menu.open();
     }
 };
 
 function _onLongPress(action, actor, state) {
-    let entry = actor._menu ? actor : actor.get_parent();
+    let entry = actor.menu ? actor : actor.get_parent();
 
     if (state == Clutter.LongPressState.QUERY)
-        return action.get_button() == 1 && !entry._menu.isOpen;
+        return action.get_button() == 1 && !entry.menu.isOpen;
 
     if (state == Clutter.LongPressState.ACTIVATE) {
         let [stageX, stageY] = action.get_coords();
         _setMenuAlignment(entry, stageX);
-        entry._menu.open();
+        entry.menu.open();
     }
     return false;
 };
 
 function _onPopup(actor) {
-    let entry = actor._menu ? actor : actor.get_parent();
+    let entry = actor.menu ? actor : actor.get_parent();
     let [success, textX, textY, lineHeight] = entry.clutter_text.position_to_coords(-1);
     if (success)
-        entry._menu.setSourceAlignment(textX / entry.width);
-    entry._menu.open();
+        entry.menu.setSourceAlignment(textX / entry.width);
+    entry.menu.open();
 };
 
 function addContextMenu(entry, params) {
-    if (entry._menu)
+    if (entry.menu)
         return;
 
-    entry._menu = new _EntryMenu(entry, params);
+    entry.menu = new EntryMenu(entry, params);
     entry._menuManager = new PopupMenu.PopupMenuManager({ actor: entry });
-    entry._menuManager.addMenu(entry._menu);
+    entry._menuManager.addMenu(entry.menu);
 
     let clickAction;